<%--
  Created by IntelliJ IDEA.
  User: LV
  Date: 2016/6/29
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>发布商品信息</title>
    <script>
        $(function ($) {
            $("#select1").children("option").remove();
            $("#select2").children("option").remove();
            $("#select3").children("option").remove();
            $("#select1").append("<option value='0'>"+"--请选择省、直辖市--"+"</option>");
            $("#select2").append("<option value='0'>"+"--请选择市、省直辖市--"+"</option>");
            $("#select3").append("<option value='0'>"+"--请选择县、区--"+"</option>");
            $.getJSON("${ctx}/areas/getAreasList/null", function(json){
                //alert("JSON Data: " +json);
                //alert(json.length);
                for(var i in json){
                    //alert(json[i].areaName);
                    $("#select1").append("<option value='"+json[i].areaCode+"'>"+json[i].areaName+"</option>");}
            });

            //省市发生改变时
            $("#select1").change(function () {
                $("#select2").children("option").remove();
                $("#select3").children("option").remove();
                $("#select2").append("<option value='0'>"+"--请选择市、省直辖市--"+"</option>");
                $("#select3").append("<option value='0'>"+"--请选择县、区--"+"</option>");
                var selectTmp=$("#select1").val();
                if(selectTmp!=0){
                    $.getJSON("${ctx}/areas/getAreasList/"+selectTmp, function(json){
                        //alert("JSON Data: " +json);
                        for(var i in json){
                            //alert(json[i].areaName);
                            $("#select2").append("<option value='"+json[i].areaCode+"'>"+json[i].areaName+"</option>");}
                    });
                }
            })

            //市区发生改变时
            $("#select2").change(function () {
                $("#select3").children("option").remove();
                $("#select3").append("<option value='0'>"+"--请选择县、区--"+"</option>");
                var selectTmp=$("#select2").val();
                if(selectTmp!=0){
                    $.getJSON("${ctx}/areas/getAreasList/"+selectTmp, function(json){
                        //alert("JSON Data: " +json);
                        for(var i in json){
                            //alert(json[i].areaName);
                            $("#select3").append("<option value='"+json[i].areaCode+"'>"+json[i].areaName+"</option>");}
                    });
                }
            })

        })
    </script>
</head>
<body>
<form>
    <table>
        <tr>
            <select id="select1">



            </select>
        </tr>

        <tr>
            <select id="select2">


            </select>
        </tr>
        <tr>
            <select id="select3">


            </select>

        </tr>
    </table>
</form>

</body>
</html>
